package com.example.lemis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.lemis.common.exception.NotFoundException;
import com.example.lemis.model.domain.Clazz;
import com.example.lemis.mapper.ClazzMapper;
import com.example.lemis.model.dto.ClazzQuery;
import com.example.lemis.model.dto.PageDTO;
import com.example.lemis.model.vo.ClazzVO;
import com.example.lemis.model.vo.PageResult;
import com.example.lemis.model.vo.StreetVO;
import com.example.lemis.service.BaseCurdService;
import com.example.lemis.service.IClazzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2025-06-24
 */
@AllArgsConstructor
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements IClazzService, BaseCurdService<Clazz> {
    private final ClazzMapper clazzMapper;

    @Override
        public ClazzVO queryOne(ClazzQuery dto) {
            Clazz entity = getOneByExample(dto);   // 一行搞定查询

            if (entity == null) {
                throw new NotFoundException("类别不存在");
            }

            ClazzVO vo = new ClazzVO();
            BeanUtils.copyProperties(entity, vo);   // 字段名 & 类型相同会自动复制
            return vo;
        }

        @Override
        public Page<ClazzVO> queryPage(ClazzQuery dto, PageDTO pageInfo) {
            Page<ClazzVO> page = new Page<>(pageInfo.getPageNo(), pageInfo.getPageSize());
            return clazzMapper.queryPage(dto, page);
        }
}
